# Release checklist
#
# Edit the version number here and in README.txt
# python setup.py build_docs
# Check in setup.py, README.txt, README.html
# python setup.py sdist upload
# Upload to google code site
# Copy README.html to blogcosm site
# Update google code homepage as needed
# svn copy -m "Tag release 0.x" https://blogmaker.googlecode.com/svn/trunk https://blogmaker.googlecode.com/svn/tags/release-0.x

import os

# Find the packages to include
try:
    from setuptools import setup, find_packages
    packages = find_packages()
    extra_kwds = dict(
        install_requires = ['Django>=0.96', 'PIL', 'markdown==1.6b'],
        
        # Note: we need Markdown 1.6b specifically. 1.6a is buggy and 1.7 is not backwards compatible
        dependency_links = ['http://sourceforge.net/project/showfiles.php?group_id=153041'],
    )
except ImportError:
    from distutils.core import setup
    packages = []
    for root, dirs, files in os.walk('.'):
        if '__init__.py' in files:
            # i.e. root='./blogmaker/blog' 
            packages.append(root.replace(os.path.sep, '.')[2:])
    extra_kwds = {}

# Package directories
package_dir = dict((pkg, pkg.replace('.', '/')) for pkg in packages)

def all_files(parent):
    ''' Return a list of data files under parent, as relative paths.
        If there are none, returns an empty list.
    '''
    data_names = 'media templates sql'.split()  # Directory names that may contain data files
    files = []
    prefix_len = len(parent) + 1

    for name in data_names:
        path = os.path.join(parent, name)
        if not os.path.isdir(path):
            continue
    
        for dirpath, dirnames, filenames in os.walk(path):
            try:
                dirnames.remove('.svn') # prune .svn dirs
            except ValueError:
                pass
            files.extend(os.path.join(dirpath, filename)[prefix_len:] for filename in filenames)
    return files
    
# Find data files associated with the packages
# This is a brute force listing of all data files
# Listing just directories doesn't work, setup isn't smart enough
# to filter out subdirectories and tries to copy them as files
package_data = {}
for pkg in packages:
        files = all_files(package_dir[pkg])
        if files:
            package_data[pkg] = files


setup(name='Blogmaker',
      version='0.6',
      description='Blog application for Django',
      author='Peter Bernheim, Kent S Johnson',
      author_email='blogmaker@blogcosm.com',
      url='http://code.google.com/p/blogmaker/',
      license='BSD License',
      keywords='django blog'.split(),
      packages=packages,
      classifiers=[
          'Development Status :: 5 - Production/Stable',
          'Environment :: Web Environment',
          'Intended Audience :: Developers',
          'License :: OSI Approved :: BSD License',
          'Natural Language :: English',
          'Operating System :: OS Independent',
          'Programming Language :: Python',
          'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
          ],
      platforms='any',
      long_description='''Blogmaker is a full-featured, production-quality blogging application for Django.
It supports trackbacks, ping, comments with moderation and 
honeypot spam prevention and many other features.''',

      package_dir=package_dir,
      package_data=package_data,
      **extra_kwds
      )
